package com.javabasic.algorithm.leetcode;

import java.math.BigInteger;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2023/12/24 23:51
 */
public class MinimumGardenPerimeterToCollectEnoughApples {


    /**
     * 数学逻辑规律算法 -- 解法1
     * 找出规律得出公式
     *
     * @param neededApples
     * @return
     */
    public long minimumPerimeter(long neededApples) {
        int side = 2;
        long squareSum = 12;
        long sum = squareSum;
        while (neededApples > sum) {
//            squareSum += side * 4 + (side + 1) * 4 + (side + 2) * 4;
            // 化简
            squareSum += (side + 1) * 12;
            sum += squareSum;
            side += 2;

            System.out.println(sum);
        }
        return side * 4;



//        BigInteger squareSum = BigInteger.valueOf(12);
//        BigInteger neededApplesBig = BigInteger.valueOf(neededApples);
//        BigInteger side = BigInteger.valueOf(2);
//        while (neededApplesBig.compareTo(squareSum) > 0) {
//
//            squareSum.add(side.multiply(BigInteger.valueOf(4).add(BigInteger.valueOf(8))));
//            side.add(BigInteger.valueOf(2));
//        }
//        return side.multiply(BigInteger.valueOf(4)).longValue();

    }
}
